package com.penfei.springrun.Service;


import com.penfei.springrun.dao.UserDao;
import com.penfei.springrun.domain.SecurityQuestionInfo;
import com.penfei.springrun.domain.UserInfo;
import com.penfei.springrun.domain.UserSecurityInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserDao userDao;

    public UserInfo getById(String id) {
        return userDao.getById(id);
    }

    public UserInfo getByPhone(String phone) {
        return userDao.getByPhone(phone);
    }

    @Transactional
    public boolean insertUser(UserInfo info) {
        userDao.insert(info);
        return true;
    }

    @Transactional
    public List<SecurityQuestionInfo> getSecurityQuestionList() {
        return userDao.getSecurityQuestionList();
    }

    @Transactional
    public boolean insertSecurity(String userId, UserSecurityInfo userSecurityInfo) {
        userDao.insertSecurity(userId, userSecurityInfo.getQuestionId1(), userSecurityInfo.getQuestionId2(), userSecurityInfo.getQuestionId3(), userSecurityInfo.getAnswer1(), userSecurityInfo.getAnswer2(), userSecurityInfo.getAnswer3());
        return true;
    }


    public UserSecurityInfo getUserSecurityById(String userId) {
        return userDao.getUserSecurityById(userId);
    }

    @Transactional
    public boolean deleteUser(String id) {
        userDao.delete(id);
        return true;
    }

    public boolean updateUser(String id, String phone, String password, String user_name, String sessionId) {
        userDao.update(id, phone, password, user_name, sessionId);
        return true;
    }
}
